package fe.pong.tennis.screens;

import fe.pong.tennis.gameElements.BackgroundMenu;
import fe.pong.tennis.gameElements.GameElement;
import motion.Actuate;
import flash.events.MouseEvent;

class MenuScreen extends Screen {

	private var b1:Button;
	private var b2:Button;
	/*private var bLeft : Button;
	private var bRight : Button;*/
	private var bIndex : Button;
	private var index : Int;

	public function new(sm:ScreenManager) {
		super(sm);
		b1 = new Button(400, 100, 0x00FF00, play, 'PLAY');
		b2 = new Button(400, 100, 0xFF0000, help, 'HELP');
		index = 1;
		bIndex = new Button(400, 100, 0x00FF00, center, index+"set >");
		/*bLeft = new Button(400, 100, 0x00FF00, left, '<');
		bRight = new Button(400, 100, 0x00FF00, right, '>');*/
		var background: GameElement = new BackgroundMenu("images/background_menu.jpg", sm.getHeigth()*2);		
		
		addChild(background);
		addChild(b1);
		addChild(b2);
		/*this.addChild(bLeft);
		this.addChild(bRight);*/
		this.addChild(bIndex);

		addLogicalChild(background);		
	}

	public function play(evento:MouseEvent) {
		_screenManager.switchScene('game');
	}

	public function help(evento:MouseEvent) {
		_screenManager.switchScene('help');
	}
	
	public function left(evento:MouseEvent) {
		if(index > 0){
			index--;
			bIndex.setLabelText(index + "set");	
		}
	}

	public function right(evento:MouseEvent) {
		if(index < 10){
			index++;
			bIndex.setLabelText(index + "set");	
		}
	}
	
	public function center(evento:MouseEvent) {		
		index++;
		index = index % 10;
		if (index == 0)
			index++;			
		bIndex.setLabelText(index + "set>");			
	}
	override public function init() {
		b1.x = _screenManager.getWidth()-450;
		b1.width = 0;
		b1.height = 0;

		b2.x = _screenManager.getWidth()-450;
		b2.width = 0;
		b2.height = 0;

		/*bLeft.x = _screenManager.getWidth()-600;
		bLeft.width = 0;
		bLeft.height = 0;*/
			
		bIndex.x = _screenManager.getWidth()-425;
		bIndex.width = 0;
		bIndex.height = 0;
		
		/*bRight.x = _screenManager.getWidth()-300;
		bRight.width = 0;
		bRight.height = 0;*/
				
		this.alpha = 0;
		b1.y = 50;
		b2.y = 150;
		//bLeft.y = 250;
		//bRight.y = 250;
		bIndex.y = 250;

		Actuate.tween(this, 0.2, { alpha:1 } );
		Actuate.tween (b1, 1, { width:400, height:100 } );
		Actuate.tween (b2, 1, { width:400, height:100 } ).delay(0.15);
		//Actuate.tween (bLeft, 1, {  width:400, height:100 } ).delay(0.15);
		Actuate.tween (bIndex, 1, { width:400, height:100 } ).delay(0.15);
		//Actuate.tween (bRight, 1, { width:400, height:100 } ).delay(0.15);
	}

	override public function end(onComplete:Dynamic) {
		this.alpha = 1;
		Actuate.tween(this, 1, { alpha:0 } ).onComplete(onComplete);
	}

}